<?php

 function crack_asia($hash)
 {
$url = "http://md5ss.sinaapp.com/md5_decode.php?decoder=5&timeout=10&hash=".$hash;
$user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";
 $ch = curl_init(); 
 curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$html = curl_exec($ch);
//var_dump($html);
 curl_close($ch);
//$html = file_get_contents($url);
//preg_match('/\346\234\252\346/',$html,$result);
//var_dump($result);

if ($html == "" or preg_match("/\346\234\252\346/",$html)) 
{

	// echo "Not found";
     return False;
}
return True;
}

//===========================================================

function crack_comcn($hash)

{

	header('Content-type:text/html;charset=utf-8');
	//1.模拟访问a.php 获取cookie
	//2.带着cookie 模拟访问b.php,取出带cookie才能获取到的值
	
	$url = 'http://www.md5.com.cn';
	$ch = curl_init($url); //初始化
	curl_setopt($ch,CURLOPT_HEADER,0); //将头文件的信息作为数据流输出
	curl_setopt ($ch,CURLOPT_REFERER,$url);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //返回获取的输出文本流
	curl_setopt($ch, CURLOPT_HEADER, 1);
	$string = curl_exec($ch);

	preg_match_all('/Set-Cookie: sessionid=.*;/i', $string, $results);
	preg_match_all('/sand"\svalue=".*"\/>/i', $string, $result_sand);
	preg_match_all('/token"\svalue=".*"\/>/i', $string, $result_token);
	// echo '<pre>';
	// print_r($results);
	//echo $string;
	//echo "=========================";
	$cookie=str_replace('Set-Cookie: ', '', $results[0][0]);
	//cookie
	$sand=str_replace('sand" value="', '', $result_sand[0][0]);
	$sand=str_replace('"/>', '', $sand);
	//sand
	$token=str_replace('token" value="', '', $result_token[0][0]);
	$token=str_replace('"/>', '', $token);
	//token

	$ch = curl_init();
	curl_setopt($ch,CURLOPT_HEADER,0);
 	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_URL, 'http://www.md5.com.cn/md5reverse');
	$data = array('md' => $hash , 'sand' => $sand , 'token' => $token , 'submit' => 'MD5+Crack' ); 
	curl_setopt($ch, CURLOPT_POST, true); 
	curl_setopt($ch, CURLOPT_COOKIE, $cookie);  //关键一句话
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
	curl_setopt ($ch,CURLOPT_REFERER,$url);
	$response = curl_exec($ch);
	curl_close($ch);
	//echo $response;
	preg_match_all('/green">.*<\/span>/i', $response, $md5_result);
	$md5_result=str_replace('green">', '', $md5_result[0][1]);
	$md5_result=str_replace('</span>', '', $md5_result);
	if (preg_match('/NotFound/',$md5_result) or $md5_result == "")
    {
    echo "Oh my fuck!";
    return False;
    }
    echo $md5_result;
    return True;


}

//===========================================================

function crack_cc($hash)
{
	header('Content-type:text/html;charset=utf-8');
    $url='http://www.md5.cc/ShowMD5Info.asp?GetType=ShowInfo&no-cache=0.4669540437658686&md5_str='.$hash.'&_=';
	//echo $url;
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_HEADER,0);
 	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
 	curl_setopt($ch, CURLOPT_URL, $url);
 	curl_setopt ($ch,CURLOPT_REFERER,'http://www.md5.cc');
 	$response=curl_exec($ch);
 	//echo $response;
 	//echo $md5_result;
    curl_close($ch);
    preg_match_all('/25px">.*<\/span>/i', $response, $md5_result);
 	//echo $md5_result[0][0];
 	//echo $md5_result;
 	$md5_result=str_replace('25px">', '', $md5_result[0][0]);
 	$md5_result=str_replace('</span>', '', $md5_result);
    $md5_result=iconv("gb2312","UTF-8",$md5_result);
    if (preg_match("/，/",$md5_result))
    {
    //echo "Not found_cc";
    return False;
    }
 	echo $md5_result;
    return True;
}

function crack_somd5($hash)
{


	$url = 'http://www.somd5.com/somd5-md5-js.html';
	$ch = curl_init($url); //初始化
	curl_setopt($ch,CURLOPT_HEADER,0); //将头文件的信息作为数据流输出
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //返回获取的输出文本流
	curl_setopt($ch, CURLOPT_HEADER, 1);
	$string = curl_exec($ch);
	preg_match_all('/isajax=.*&/i', $string , $ajax_data);
	$ajax_data=str_replace('isajax=', '', $ajax_data[0][0]);
	$ajax_data=str_replace('&', '', $ajax_data);

	//$ch = curl_init();
	curl_setopt($ch,CURLOPT_HEADER,0);
 	curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_URL, 'http://www.somd5.com/somd5-index-md5.html');
	$data = array('isajax' => $ajax_data , 'md5' => $hash); 
	curl_setopt($ch, CURLOPT_POST, true); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
	$response = curl_exec($ch);
	//echo $response;
	preg_match_all('/<h1.*inline;">.*<\/h1>/i', $response , $md5_result);
	$md5_result=str_replace('<h1 style="display:inline;">', '', $md5_result[0][0]);
 	$md5_result=str_replace('</h1>', '', $md5_result);
    if ($md5_result == "")
    {
       // echo "Not found_somd5";
        return False;
    }
    echo $md5_result;
    return True;
}


#crack_somd5('80c9ef0fb86369cd25f90af27ef53a9e');;
header('Content-type:text/html;charset=utf-8');
$hash = $_POST['hash'];
if ($hash != "")
{

if (!crack_somd5($hash))
    {
    if (!crack_cc($hash))
  {
    if (!crack_asia($hash))
    {
         if (!crack_comcn($hash))
        {
        echo "======";
        }
    }
  }
    }
}

?>
